package com.bs.web.rest;

import com.bs.domain.Partitions;
import com.bs.service.PartitionsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * REST controller for managing Partitions.
 */
@RestController
@RequestMapping("/api/partitions")
public class PartitionsResource {

    @Autowired
    private PartitionsService service;
    private final Logger log = LoggerFactory.getLogger(PartitionsResource.class);

    @PostMapping("/search")
    @ResponseBody
    public List<Partitions> search(@RequestBody Partitions partitions){
        List<Partitions> partitionss= service.getPartitionss(partitions);
        Collections.sort(partitionss,(Partitions a, Partitions b)->b.getFname().compareTo(a.getFname()));
        return partitionss;
    }

    @PostMapping("/save")
    public void save(@RequestBody Partitions partitions){
        service.save(partitions);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody Partitions partitions){
        service.delete(partitions);
    }

}
